package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsRegionMapper;
import com.qf.pojo.DtsRegion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author fy
 * @version V1.0
 * @Project workspace
 * @Package com.qf.service
 * @Description:
 * @Date 2022/6/21 17:04
 */
@Service
public class RegionServiceImpl implements RegionService {
    @Autowired
    private DtsRegionMapper regionMapper;

    @Override
    public IPage<DtsRegion> queryRegionPage(String name, Integer code, Integer page, Integer limit) {
        //1.创建分页对象
        IPage<DtsRegion> iPage = new Page<>(page,limit);
        //2.封装查询对象
        QueryWrapper<DtsRegion> queryWrapper = new QueryWrapper<>();
        //姓名不为空，校验
        if (!StringUtils.isEmpty(name)){
            queryWrapper.like("name", name);
        }
        //code不为空，校验
        if (!StringUtils.isEmpty(code)){
            queryWrapper.eq("code", code);
        }

        //3.查询并返回结果
        IPage<DtsRegion> resultPage = regionMapper.selectPage(iPage, queryWrapper);

        return resultPage;
    }
}
